﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.SharePoint;

namespace ServerExplorer.SharePointConnections.SharepointSiteInfo.Entities
{
    [Serializable]
    public class Web
    {        
        private string _guid;

        [XmlAttribute("Guid")]
        public string Guid
        {
            get { return _guid; }
            set { _guid = value; }
        }

        private string _folderName;

        [XmlAttribute("Name")]
        public string FolderName
        {
            get { return _folderName; }
            set { _folderName = value; }
        }

        private string _webURL;

        [XmlAttribute("Url")]
        public string WebURL
        {
            get { return _webURL; }
            set { _webURL = value; }
        }

        private List<Folder> _folders;

        [XmlElement("Folder")]
        public List<Folder> Folders
        {
            get { return _folders; }
            set { _folders = value; }
        }

        private SubWebs _subSites;

        [XmlElement("SubSite")]
        public SubWebs SubSites
        {
            get { return _subSites; }
            set { _subSites = value; }
        }

        private bool _isRootWeb;

        [XmlAttribute("Color")]
        public string Color
        {
            get
            {
                string color = "Black";
                if (_isRootWeb)
                {
                    color = "Gray";
                }
                return color;
            }
            set
            { //do nothing
            }
        }

        private List<Page> _pages;

        [XmlElement("Page")]
        public List<Page> Pages
        {
            get { return _pages; }
            set { _pages = value; }
        }


        [XmlIgnore]
        public bool IsRootWeb
        {
            get { return _isRootWeb; }
            set { _isRootWeb = value; }
        }



        private Web(String[] obj)
            : this()
        {
            _folderName = obj[0];
            _webURL = obj[1];
            _guid = obj[2];
            //if()
        }
        
        public Web()
        {
            _folders = new List<Folder>();
            _subSites = new SubWebs();
            _pages = new List<Page>();
            _isRootWeb = false;
        }

        public static implicit operator Web(String[] obj)
        {
            return new Web(obj);
        }

        public override string ToString() { return WebURL; }
    }
}
